<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns="http://www.w3.org/1999/xhtml">
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>智能文本分析及质检系统</title>
    <link rel="stylesheet" href="../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
    <link rel="stylesheet" href="../../assert/css/animate.min.css" th:href="@{/assert/css/animate.min.css}"/>
    <link rel="stylesheet" href="../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link rel="stylesheet" href="../../assert/js/layui/css/layui.css" th:href="@{assert/js/layui/css/layui.css}"
          media="all">
    <link rel="stylesheet" href="../../assert/css/bootstrap-table.css" th:href="@{/assert/css/bootstrap-table.css}"/>
    <link href="../../assert/css/loaders.css" rel="stylesheet" th:href="@{/assert/css/loaders.css}">
    <link rel="stylesheet" href="../../assert/css/index.css" th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"/>
    <script th:inline="javascript">
        /*<![CDATA[*/
        var firstLogin = [[${session[T(com.thinkit.bigdata.web.model.result.Constants).FIRST_LOGIN]}]]+"";
        if("true"==firstLogin){
            window.location.href=/*[[@{/rest/page/password}]]*/+"";
        }
        var js_version = [[${js_version}]]+"";
//        var setTime=new Date([[${session[T(com.thinkit.bigdata.web.model.result.Constants).SESSION_USER_INFO]["pswsettime"]}]]).getTime();
        /*]]>*/
    </script>
</head>
<body id="body">
<!--头部-->
<div class="header-box">
    <div id="homeIcon" title="首页"></div>
    <div class="title">
        <span class="projectName">智能文本分析及质检系统</span>
        <span class="fa fa-reorder menuBtn" title="展开"></span>
    </div>
    <div class="pswTip animated bounceInRight" style="display: none"><span class="fa fa-exclamation-circle"></span><b></b>
        <a href="" class="J_menuItem" target="_blank" title="查看详情" data-href="/rest/page/userMessage" data-index="21"
           data-txt="个人设置">重置密码</a> ！<i class="fa fa-times"></i></div>
    <ul class="header-icon">
        <li  id="spanId"></li>
        <li  id="helpButton" title="帮助文档">帮助中心</li>
        <li  id="logoutButton" title="退出质检系统">退出</li>
    </ul>
</div>
<div class="content-box">
<!--    左侧菜单-->
    <div class="layui-side">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="demo" style="margin-right: 10px;">
                <li class="layui-nav-item layui-this mainP"><a href="javascript:;" class="J_menuItem"
                                                               data-href="/rest/page/main" data-index="0"><span
                        class="fa fa-home"></span>首页</a></li>
            </ul>
        </div>
    </div>
<!--    主内容-->
    <div class="content_right">
        <div class="content-tabs">
            <button class="roll-nav roll-left J_tabLeft"><i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs J_menuTabs">
                <div class="page-tabs-content">
                    <a href="javascript:;" class="active J_menuTab main" data-code="/rest/page/main"
                       data-index="0">首页</a>
                </div>
            </nav>
            <button class="roll-nav roll-right J_tabRight"><i class="fa fa-forward"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown J_tabClose" data-toggle="dropdown">关闭操作<span class="caret"></span></button>
                <ul role="menu" class="dropdown-menu dropdown-menu-right">
                    <li class="J_tabShowActive"><a>定位当前选项卡</a>
                    </li>
                    <li class="divider"></li>
                    <li class="J_tabCloseAll"><a>关闭全部选项卡</a>
                    </li>
                    <li class="J_tabCloseOther"><a>关闭其他选项卡</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="J_mainContent" id="content-main">
            <iframe src="" frameborder="0" class="J_iframe" name="iframe0"></iframe>
        </div>
    </div>
</div>
<div th:text="${session.userIdentity}" id="userIdentity" class="hidden"></div>
<div th:if="${session.areaInfo!=null}" th:text="${session.areaInfo.id}" id="areaInfo" class="hidden"></div>
<a id="basePath" th:href="@{/}"></a>
<shiro:hasPermission name="JUMP_AUDIO">
    <button class="fa-btn btn-primary hidden" id="isJumpBtn">是否可以跳转语音详情</button>
</shiro:hasPermission>
</body>
<script src="../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/layui/layui.all.js" th:src="@{/assert/js/layui/layui.all.js}"></script>
<script src="../../assert/js/contabs.min.js" th:src="@{/assert/js/contabs.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/changeTime.js" th:src="@{/assert/js/changeTime.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/base.js" th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script th:inline="javascript">
    //清除缓存
    var clearCache={
        init:function(){
            var scriptArr=[
                {"src":/*[[@{/app/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}]]*/+""},
                {"src":/*[[@{/assert/js/contabs.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}]]*/+""},
                {"src":/*[[@{/assert/js/changeTime.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}]]*/+""}
            ];
            clearCache.renderScript(scriptArr);
        },
        renderScript:function(arr){
            var oFragmeng = document.createDocumentFragment();
            var num=0;
            for(var i=0;i<arr.length;i++){
                var src=arr[i].src;
                var script = document.createElement('script');
                script.type = 'text/jacascript';
                script.src = src+"?t="+ js_version;     //填自己的js路径
                script.defer=true;
                oFragmeng.appendChild(script);
                $.getScript(script.src, function(){
                    num++;
                });
            }
            document.head.appendChild(oFragmeng)
            if(num==arr.length){

            };
        }
    };
//    clearCache.init();
</script>
<script th:inline="javascript">
    //项目名称
    var basePath = $("#basePath").attr("href");
    //    获取系统配置（规则页面路径）
    var getData = {
        ruleUrl: "",
        cacheCode:"",
        getConfig: function () {
            var data = bs.getSysConfig("RULE_ACCESSORY_URL");
            var a = document.createElement('a');
            a.href = data.value ;
            getData.ruleUrl = a.href;
        }
    };
    // 密码提示
    var pswTip={
       getPwdUpTime:function(){
           var setTime;
           $.ajax({
               type:"get",
               url:basePath + "rest/users/passSetTime",
               async:false,
               success:function(data){
                   setTime=data;
               }
           });
           return setTime;
       },
       init:function(){
           $(".pswTip").hide();
           var setTime=pswTip.getPwdUpTime();
           var pswDay=parseInt(bs.getSysConfig("PSW_TIP").value);//密码还有多少天提醒
           var pswEndDay=parseInt(bs.getSysConfig("PSW_MAX_DAY").value);//密码有效期90天
           var durDay=pswEndDay-pswDay;
           var nowTime=new Date().getTime();
           var pswEnds=pswEndDay*24*3600*1000+setTime;
           var pswEndDate=dateFormatUtil(pswEnds);
           if(nowTime>setTime){
               var dur= pswEnds-nowTime;
               var day=dur/1000/3600/24;
               if(day<=durDay){
                   var reDay=(pswEnds-nowTime)/1000/3600/24;
                   $(".pswTip b").html("密码于 "+pswEndDate+"（"+parseInt(reDay)+"天后）过期 ，请及时");
                   $(".pswTip").show();
               }
           }
           $(".pswTip a").attr("href", basePath + "/rest/page/userMessage").on("click",function(){
               var index=$(this).attr("data-index");
               var tabOnElem= $(".J_menuItem[data-index='"+index+"']");
               if(!tabOnElem.parents(".layui-nav-item").hasClass("layui-nav-itemed")){
                   tabOnElem.parents(".layui-nav-item").addClass("layui-nav-itemed");
               }
               $(".layui-this").removeClass("layui-this");
               tabOnElem.parent().addClass("layui-this");
               $(".J_menuTab[data-index='"+index+"']").click();
           });
           $(".pswTip i").on("click",function(){
               $(this).parent().hide();
           })
       }
    };
    // 左侧菜单渲染
    var menuMain = {
        arr: [],
        init: function () {
            menuMain.getMenuData();
        },
        getMenuData: function () {
            //    获取所有左侧菜单
//            $.get(basePath + "rest/resource/parentResourceAll", function (data) {
            $.get(basePath + "rest/permission/indexMenuInit", function (data) {
                menuMain.rootLoopMenu(data);
                menuMain.renderMenu(menuMain.arr);
                menuMain.renderHtml();
            });
        },
        rootLoopMenu: function (array) {
            // 先构建一级菜单 防止先读取到二级菜单时 二级菜单没有被处理
            if(array.length > 0){
                for (var i = 0; i < array.length; i++) {
                    var obj = {};
                    var parentid = array[i].parentid;
                    var id = array[i].id;
                    var name = array[i].name;
                    var code = array[i].code;
                    var imgspan = array[i].imgspan;
                    var url = array[i].url;
                    obj.id = id;
                    obj.parentid = parentid;
                    obj.text = name;
                    obj.imgspan = imgspan;
                    obj.url = url;
                    obj.code = code;
                    if (parentid == null) {
                        obj.children = [];
                        menuMain.arr.push(obj);
                    }
                }
                // 处理二级菜单
                for (var i = 0; i < array.length; i++) {
                    var obj = {};
                    var parentid = array[i].parentid;
                    var id = array[i].id;
                    var name = array[i].name;
                    var imgspan = array[i].imgspan;
                    var url = array[i].url;
                    var code = array[i].code;
                    obj.id = id;
                    obj.parentid = parentid;
                    obj.text = name;
                    obj.imgspan = imgspan;
                    obj.url = url;
                    obj.code = code;
                    if (parentid != null) {
                        if (menuMain.arr.length > 0) {
                            for (var j in menuMain.arr) {
                                var pid = menuMain.arr[j].id;
                                if (pid == parentid) {
                                    obj.children = [];
                                    menuMain.arr[j].children.push(obj);
                                }
                            }
                        }
                    }
                }
            }
        },
        renderMenu: function (array) {
            var ulBox = $(".layui-nav");
            if (array && array.length > 0) {
                for (var i = 0; i < array.length; i++) {
                    var id = array[i].id;
                    var name = array[i].text;
                    var code = array[i].code;
                    var imgspan = array[i].imgspan;
                    var children = array[i].children;
                    var parentid = array[i].parentid;
                    var url = basePath + array[i].url;
                    var $li;
                    var $dd;

                    if (parentid == null) {
                        if (url.indexOf("rest") > -1) {
                            $li = $('<li class="layui-nav-item" data-id="' + id + '">' +
                                '<a  href="' + url + '" class="J_menuItem" data-href="' + url + '" data-index="' + i + '" title="'+name+'"><span class="' + imgspan + '"></span>' + name + '</a>' +
                                '</li>');
                        } else {
                            $li = $('<li class="layui-nav-item" data-id="' + id + '"><a href="javascript:;" title="'+name+'"><span class="' + imgspan + '"></span>' + name + '<span class="layui-nav-more"></span></a><dl class="layui-nav-child"></dl></li>');
                        }
                        ulBox.append($li);
                    } else {
                        if (code == "ZJPZ_GZGL" || code == "ZJPZ_MXGL") {
                            //获取系统配置（规则页面路径）
                            if(!getData.ruleUrl){
                                getData.getConfig();
                            }
                        }
                        if (code == "ZJPZ_GZGL"){
                            url = getData.ruleUrl;
                        }
                        $dd = $('<dd><a href="' + url + '"  class="J_menuItem" data-href="' + url + '" data-index="' +i+ i + parentid + '" title="'+name+'">' + name + '</a></dd>');
                        ulBox.find("li[data-id='" + parentid + "'] dl").append($dd);
                    }
                    if (children) {
                        menuMain.renderMenu(children);
                    }
                }
            }
        },
        renderHtml:function(){
            layui.use(['element', 'table'], function () {
                var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
                //监听导航点击
                element.init();
                element.on('nav(demo)', function (elem) {
                    userNameShow.nameShow();
                    if ($(".layui-side").width() == 50) {//点击的时候展开左菜单
                        $(".layui-side").animate({"width": "200px"}, 300);
                        $(".content_right").css({"margin-left": "200px"});
                        $(".content_right").animate({"width": ($(window).width() - 200) + "px"}, 300);
                    }
                    if ($(elem).attr("data-index") == "007") {//如果是规则管理 需要给规则所传所需参数
                        var obj = {};
                        obj.provinceCode = $("#spanId").attr("data-procode");
                        obj.userId = $("#spanId").attr("data-userid");
                        obj.userName = $("#spanId").attr("title");
                        sessionStorage.setItem("ruleManager", JSON.stringify(obj));
                    }
                    if ($(elem).text() == "个人中心") {//如果是待办任务 需要显示新数据提示 小红点
//                       menuMain.renderDot();
                    }
                });
//                根据上次打开页面记录 刷新记录页面
                var obj=JSON.parse(sessionStorage.getItem("htmlMsg"));
                if(obj){
                    var tabOnElem= $(".J_menuItem[data-index='"+obj["index"]+"']");
                    if(!tabOnElem.parents(".layui-nav-item").hasClass("layui-nav-itemed")){
                        tabOnElem.parents(".layui-nav-item").addClass("layui-nav-itemed");
                        if(tabOnElem.parents(".layui-nav-item").children("a").text()=="个人中心"){
//                            menuMain.renderDot("");
                        }
                    }
                    $(".layui-this").removeClass("layui-this");
                    tabOnElem.parent().addClass("layui-this");
                    tabOnElem.click();
                    tabOnElem.click();
                }
            });
        },
        renderDot:function(workId){
            var url = basePath + "rest/pending-task/get-mes";
            $.post(url,function (data) {
                if (data.data != 0) {
                    if($(".J_menuItem[data-index='01']").parent().find(".dotRed").length<=0){
//                        $(".J_menuItem[data-index='01']").parent().append("<i class='dotRed'>"+data.data+"</i>");
                        $(".J_menuItem[data-index='01']").parent().append("<i class='dotRed'></i>");
                    }
                } else {
                    $(".J_menuItem[data-index='01']").parent().find(".dotRed").remove();
                }
            });
        }
    };
    // 给菜单赋值跳转路径
    var editMenuHref = {
        init: function () {
            $("iframe[name='iframe0']").attr("src", basePath + "/rest/page/main").attr("data-id", basePath + "/rest/page/main");
            $(".main").attr({"data-id": basePath + $(".main").attr("data-code")});
            $(".mainP a").attr({"href": basePath + "/rest/page/main"});
        }
    };
    // 自适应
    var resize = {
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            $(".content-box").height(winH - $(".header-box").height());
            $(".content_right").width(winW - $(".layui-side").width());
            $(".content_right").height(winH - 60 + 5);
            $(".J_mainContent").height(winH - 60 - 33);
        },
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        }
    };
    //页面初始化
    var htmlInit = {
        isEnableLeftMenu: "true",
        init: function () {
            //点击提示框的关闭按钮，删除提示框
            $("body").on("click", "span.glyphicon-remove", function () {
                $(this).parents("div.prompt").hide().remove();
                $(this).parents("div.promptError").hide().remove();
                $(this).parents("div.promptWarn").hide().remove();
            });
        }
    };
    //显示用户名
    var userNameShow = {
        init: function () {
            userNameShow.nameShow();
        },
        nameShow: function () {
            var url = basePath + "/rest/users/passwordSale";
            $.post(url, function (data) {
                var msg = data.data;
                $("#userIdentity").html(msg.userIdentity);
                $("#areaInfo").html(msg.areaId);
                sessionStorage.setItem("spanId",msg.userName);
                sessionStorage.setItem("procode",msg.code);
                sessionStorage.setItem("areaId",msg.areaId);
                $("#spanId").html("你好，" + msg.userName).attr("title", msg.userName).attr("data-userId", msg.id).attr("data-procode", msg.code);
            });
        }
    };
    //退出操作
    var logout = {
        init: function () {
            logout.logoutFu();
        },
        logoutFu: function () {
            $('#logoutButton').click(function () {
                // 退出清除页面session
                sessionStorage.clear();
                location.href = basePath + "/rest/user/logout";
            });
            $('#helpButton').click(function () {
//                location.href = basePath + "/rest/page/help";
                window.open(basePath + "/rest/page/help")
            });
        }
    };
    //菜单横纵伸缩
    var menuExpansion = {
        time: null,
        init: function () {
            menuExpansion.portraitExpansion();
//            menuExpansion.transverseExpansion();
        },
        //菜单纵向伸缩
        portraitExpansion: function () {
            $(".menuBtn").unbind("click").on("click", function () {
                $(".layui-nav-item").removeClass('layui-nav-itemed')
                if ($(".layui-side").width() !== 50) {
                    $(".layui-side").animate({"width": "50px"}, 300);
                    $(".content_right").css({"margin-left": "50px"});
                    $(".content_right").animate({"width": ($(window).width() - 50) + "px"}, 300);
                } else {
                    $(".layui-side").animate({"width": "200px"}, 300);
                    $(".content_right").css({"margin-left": "200px"});
                    $(".content_right").animate({"width": ($(window).width() - 200) + "px"}, 300);
                }

            });
        },
        //菜单横向伸缩
        transverseExpansion: function () {
            $(".aside").hover(function () {
                $(".content-list > li > a b").css("opacity", "1");
                $(".aside").stop().animate({"width": "200px"}, 200);
            }, function () {
                $(".content-list > li > a b").css("opacity", "0");
                $(".aside").stop().animate({"width": "56px"}, 200);
            })
        }
    };
    //菜单
    var animate = { //菜单
        init: function () {
            animate.menuModal();//模块动画
        },
        menuModal: function () {
            $("ul.list>li").each(function () {
                $(this).addClass("animated fadeInDown");
            });
        }
    };
    //显示模态框
    function showModal(obj) {
        if (obj) {
            $("#" + obj).modal('show');
        }
    }
    $(function () {
        $("iframe").attr("src", basePath + "/rest/page/main");
        resize.init();
        //左侧菜单
        menuMain.init();
        //初始化
        htmlInit.init();
        //给菜单赋值跳转路径
        editMenuHref.init();
        //显示用户名
        userNameShow.init();
        //退出操作
        logout.init();
        //菜单伸缩
        menuExpansion.init();
        //密码过期提示
        pswTip.init();
    });
    $(window).on('beforeunload', function () {
        var htmlMsg=sessionStorage.getItem("htmlMsg");
        var index=$(".layui-this").children("a").attr("data-index");
        var obj={};
        if(!htmlMsg){
            obj.index=0;
            sessionStorage.setItem("htmlMsg", JSON.stringify(obj));
        }else{
            obj.index=index;
            sessionStorage.setItem("htmlMsg", JSON.stringify(obj));
        }
    });
    document.addEventListener('visibilitychange', function () {
        if (document.hidden) {

        } else {
            var url = basePath + "/rest/users/passwordSale";
            $.post(url, function (data) {
                var msg = data.data;
                if($("#spanId").attr("data-userid")!=msg.id){
                    location.reload();
                }
            });
        }
    });
</script>
